
var _oEntitiesXml = null;
var _oAllFieldsXml = null;
var _oAllFieldPropertiesXml = null;
function Init()
{

addSortingToLookupView();


crmFormSubmit.attachEvent("onsubmit", ValidateView);

var oFieldNodeList = oGridXml.selectSingleNode("/grid/row").childNodes;
for (var i = 0; i < oFieldNodeList.length; i++)
{
var newTd = CreateFieldCell(oFieldNodeList.item(i));
cellsRow.appendChild(newTd);
}
cellsRow.appendChild(document.createElement("<td></td>"));

UpdateSortingUI();

UpdateDataArea();
}
function UpdateDataArea()
{

var iDataAreaWidth = 0;
for (var i = 0 ; i < cellsRow.cells.length - 1; i++)
{
iDataAreaWidth += Number(cellsRow.cells[i].width);
}
tblDataAreaStretcher.width = (iDataAreaWidth == 0) ? 1 : iDataAreaWidth;
}
function CreateFieldCell(oCell)
{
var sFieldName			= oCell.getAttribute("name");
var oFieldInfo			= GetFieldInfo(sFieldName);
var sEntityName			= oFieldInfo.EntityName;
var sFieldDisplayName	= formatString(oFieldInfo.GridFieldDisplayMask, oFieldInfo.InvalidField ? sFieldName : oFieldInfo.DisplayName);
var iWidth				= Number(oCell.getAttribute("width"));
iWidth					= (iWidth <= 0) ? 100 : iWidth;
var sTitle				= formatString(LOCID_VIEWEDITOR_COLTOOLTIP, sFieldDisplayName);
var sErrTitle			= LOCID_VIEWEDITOR_COLERR_TOOLTIP;
var sErrImg				= "<IMG alt='" + CrmEncodeDecode.CrmHtmlAttributeEncode(sErrTitle) + "' src='/_imgs/error/notif_icn_warn16.png' onclick='alert(this.alt)'/>&nbsp;";
var sNewTdHTML			= formatString(
"<td name='{0}' width='{1}' onclick='SetActiveObject(this);' ondblclick='ViewColumnProperties();'></td>",
CrmEncodeDecode.CrmHtmlAttributeEncode(sFieldName), iWidth + 3);
var sNewTdInnerHTML		= formatString(
"<table cellspacing='0' cellpadding='0' style='table-layout:fixed;width:100%;height:100%;'>" +
"<col/><col width='6px'/>" +
"<tr>" +
"<td id='tdFieldName' title=\"{0}\" class='viewManager_js_td'>" +
"<a href='#' title=\"{0}\"><nobr>" +
"{2}{1}" +
"<img alt='' id='imgSort' src='/_imgs/grid/bar_up.gif' class='ms-crm-List-Sortable addFields_img_barUp' style='visibility:hidden'/>" +
"</nobr></a>" +
"</td>" +
"<td align='middle'>" +
"<img alt='' src='/_imgs/grid/bar_line.gif' align='absmiddle'/>" +
"</td>" +
"</tr>" +
"</table>",
CrmEncodeDecode.CrmHtmlAttributeEncode(oFieldInfo.InvalidField ? sErrTitle : sTitle), CrmEncodeDecode.CrmHtmlEncode(sFieldDisplayName),
oFieldInfo.InvalidField ? sErrImg : "");
var newTd				= document.createElement(sNewTdHTML);
newTd.innerHTML			= sNewTdInnerHTML;
return newTd;
}
function ViewProperties(mode)
{
if (!_bInitialized)
{
return;
}
var aViewInfo;


if (!IsNull(crmForm.iscustomizable))
{
aViewInfo = new Array(crmForm.name.value, crmForm.description.value, crmForm.iscustomizable.value, crmForm.querytype.value);
}
else
{


aViewInfo = new Array(crmForm.name.value, crmForm.description.value, "1", crmForm.querytype.value);
}
aViewInfo = openStdDlg(prependOrgName("/Tools/ViewEditor/Dialogs/ViewProperties.aspx?mode=" + mode), aViewInfo, 500, 310);
if (aViewInfo)
{
crmForm.name.value = aViewInfo[0];
crmForm.description.value = aViewInfo[1];
}
else if (mode == "new")
{
alert(LOCID_VIEWEDITOR_BASICINFO);
crmForm._bSaving = true;
window.close();
}
}
function Remove(oActive)
{
if (!_bInitialized)
{
return;
}
if (!oActive)
{
alert(LOCID_VIEWEDITOR_RMSELECTCOLUMN);
return;
}
if (oActive.name == _requiredColumn)
{
alert(LOCID_VIEWEDITOR_CANTRMREQCOL);
return;
}
else if (confirm(LOCID_VIEWEDITOR_REMOVECOLUMN))
{
RemoveField(oActive);
}
}
function ViewColumnProperties()
{
ColumnProperties(_oActive);
}
function SetActiveObject(o)
{
var s = "2px solid #23b30c";
if (_oActive)
{
_oActive.all["tdFieldName"].style.border = "";
}
o.all["tdFieldName"].style.border = s;
_oActive = o;
}
function HandleScroll()
{
divGridCols.scrollLeft = event.srcElement.scrollLeft;
}
function GetEntityIdFromQuery()
{

var queryString = window.location.search.substring(1);
var pairs = queryString.split("&");
var entityId = "";
for (var i = 0; i < pairs.length; i++)
{
var position = pairs[i].indexOf('=');
if (position >= 0)
{
if(pairs[i].substring(0,position) == "entityId")
{
entityId = pairs[i].substring(position + 1);
break;
}
}
}
return CrmEncodeDecode.CrmUrlEncode(entityId);
}
function AddColumns(oActive, bQuickFindMode)
{
if (!_bInitialized)
{
return;
}
var oArgs = new Object();
oArgs.PrimaryEntityName		= _sPrimaryEntityName;
oArgs.FieldsXml				= oFieldsXml;
oArgs.FieldPropertiesXml	= oPropertiesXml;
oArgs.GridXml				= oGridXml;

oArgs.bQuickFindMode		= bQuickFindMode;
var sURL = prependOrgName("/Tools/ViewEditor/Dialogs/AddColumns.aspx?mode=");
sURL += (oArgs.bQuickFindMode ? "qfaddcol" : "viewaddcol");
sURL += "&entityId=" + GetEntityIdFromQuery();
oArgs.ShowRelatedEntities = false;

if(!bQueryAPIBasedView)
{
oArgs.ShowRelatedEntities = true;
oArgs.EntitiesXml = oEntitiesXml;
oArgs.FetchXml = oFetchXml;
}
var oReturnValue = openStdDlg(sURL, oArgs, 570, 450);
var oFieldObjs = oReturnValue;
if(!IsNull(oFieldObjs) && oArgs.ShowRelatedEntities)
{
with(oReturnValue)
{
var oFieldObjs = FieldObjs;
oFieldsXml = FieldsXml;
oPropertiesXml = FieldPropertiesXml;
}
}

if (oFieldObjs)
{
for (var i = (oFieldObjs.length - 1); i >= 0; i--)
{

if (!oActive) oActive = cellsRow.cells[cellsRow.cells.length - 2];
AddField(oActive, oFieldObjs[i]);
}

UpdateFormData();
}
}

function EditQuickFindFields()
{
if (!_bInitialized)
{
return;
}
var oArgs = new Object();
oArgs.PrimaryEntityName		= _sPrimaryEntityName;
oArgs.FieldsXml				= oFieldsXml;
oArgs.FieldPropertiesXml	= oPropertiesXml;
oArgs.GridXml				= oGridXml;
oArgs.FetchXml				= oFetchXml;

oArgs.bQuickFindMode		= true;
oArgs.ShowRelatedEntities	= false;

var bQFValidFieldExists = false;
var oFieldObjs = openStdDlg(prependOrgName("/Tools/ViewEditor/Dialogs/AddColumns.aspx?mode=qfaddsearch&entityId=" + GetEntityIdFromQuery()), oArgs, 570, 450);
if (oFieldObjs)
{

var sOperator, sValue;

var sFilterXml = "<filter type='or' isquickfindfields='1'>";
for (var i = (oFieldObjs.length - 1); i >= 0; i--)
{


sOperator = "";
sValue = "";
switch(oFieldObjs[i].DataType)
{
case "text":
case "memo":
case "boolean":
case "lookup":
case "owner":
case "customer":
case "picklist":
case "state":
case "status":
sOperator = "like";
sValue = "{0}";
break;

case "integer":
sOperator = "eq";
sValue = "{1}";
break;

case "money":
sOperator = "eq";
sValue = "{2}";
break;

case "datetime":
sOperator = "on";
sValue = "{3}";
break;

case "float":
sOperator = "eq";
sValue = "{4}";
break;

default:

continue;
}
bQFValidFieldExists = true;
sFilterXml += "<condition attribute=\"" + oFieldObjs[i].FieldName + "\" operator=\"" + sOperator + "\" value=\"" + sValue + "\"/>";
}

sFilterXml += "</filter>";


if(!bQFValidFieldExists)
{
alert(LOCID_VIEWEDITOR_QFINVALIDFIELDS);
return;
}

_oXmlDoc = loadXmlDocument(sFilterXml);

var oOldFilter = oFetchXml.selectSingleNode("/fetch/entity//filter[@isquickfindfields=1]");


if(!IsNull(oOldFilter))
{

oOldFilter.parentNode.replaceChild(_oXmlDoc.selectSingleNode("filter"), oOldFilter);
}
else
{

oFetchXml.selectSingleNode("/fetch/entity").appendChild(_oXmlDoc.selectSingleNode("filter"));
}

UpdateFormData();
}
}
function ColumnProperties(oActive)
{
if (!_bInitialized)
{
return;
}
if (oActive == null)
{
alert(LOCID_VIEWEDITOR_EDSELECTCOLUMN);
}
else
{
var sFieldName = oActive.name;
var size;
var oFieldInfo;
var oArgs;
try
{
oFieldInfo			= GetFieldInfo(sFieldName);
oArgs				= new Object();
oArgs.fieldDesc		= formatString(oFieldInfo.GridFieldDisplayMask, oFieldInfo.DisplayName);
oArgs.entityDesc	= oFieldInfo.EntityDisplayName;
oArgs.fieldType		= oFieldInfo.Type;
oArgs.sSchemaName	= oFieldInfo.SchemaName;
size = GetGridCellNode(oGridXml, sFieldName).getAttribute("width");
}
catch (e)
{
alert(formatString(LOCID_VIEWEDITOR_INVALIDCOLUMN, sFieldName));
return false;
}

var oFieldSizes = new Object();
for (var i = 0; i < cellsRow.cells.length; i++)
{

var sSipFieldName = cellsRow.cells[i].name;
if (sSipFieldName != null)
{
if (sSipFieldName.indexOf("internalemailaddress") >= 0 || sSipFieldName.indexOf("emailaddress1") >= 0)
{
oFieldSizes[sSipFieldName] = GetGridCellNode(oGridXml, sSipFieldName).getAttribute("width");
}
}
}
oArgs.EntitiesXml = oEntitiesXml;
oArgs.FieldSizes = oFieldSizes;


if (size == null)
{
size = "";
}
var oReturnValue = openStdDlg(prependOrgName("/Tools/ViewEditor/Dialogs/ColumnProperties.aspx?size=" + CrmEncodeDecode.CrmUrlEncode(size) + "&entityName=" + CrmEncodeDecode.CrmUrlEncode(oFieldInfo.EntityName) + "&attributeName=" + CrmEncodeDecode.CrmUrlEncode(oFieldInfo.SchemaName) + "&FromExportExcel=" + _bFromExportExcel), oArgs, 475, 500);
if (!IsNull(oReturnValue))
{
if (size != oReturnValue.Size)
{
GetGridCellNode(oGridXml, sFieldName).setAttribute("width") = oReturnValue.Size;
oActive.width = oReturnValue.Size;
}

if (oReturnValue.PresenceEnabled != null)
{

if (oReturnValue.RelationshipId == "")
{
if (oReturnValue.PresenceEnabled)
{
AddSipColumn(oReturnValue.FieldName, null, oReturnValue.EntityName);
}
else
{

RemoveSipColumn(oReturnValue.FieldName);
}
}
else
{

var sAlias = "";
var oAlias = oEntitiesXml.selectSingleNode("entities/entity[@relid=\"" + oReturnValue.RelationshipId + "\"]/@alias");
if (oAlias != null)
{
sAlias = oAlias.value;
}
if (sAlias !== "")
{
if (oReturnValue.PresenceEnabled)
{
AddSipColumn(oReturnValue.FieldName, sAlias, oReturnValue.EntityName);

GetFieldsXmlInternal(oReturnValue.EntityName, sAlias, oGridXml, oArgs.bQuickFindMode, false, false, false);
}
else
{

RemoveSipColumn(sAlias + "." + oReturnValue.FieldName);
}
}
}
}
UpdateDataArea();
UpdateFormData();
}
}
}
function AddSipColumn(sFieldName, sRelationshipId, sEntityName)
{

var oActive = cellsRow.cells[cellsRow.cells.length - 2];

var oFieldObj = new Object();
oFieldObj.FieldName = sFieldName;
oFieldObj.RelationshipId = sRelationshipId;
oFieldObj.EntityName = sEntityName;
var oldActive = _oActive;
AddField(oActive, oFieldObj, 10);
SetActiveObject(oldActive);
_oEntitiesXml = oEntitiesXml;
_oAllFieldsXml = oFieldsXml;
_oAllFieldPropertiesXml = oPropertiesXml;
}

function RemoveSipColumn(sFieldName)
{
var oActive = GetRelatedSipCell(sFieldName);
if (oActive != null)
{
var oldActive = _oActive;
RemoveField(oActive);
SetActiveObject(oldActive);
}
}
function GetRelatedSipCell(sFieldName)
{
for (var i = 0; i < cellsRow.cells.length; i++)
{
if (cellsRow.cells[i].name === sFieldName)
{
return cellsRow.cells[i];
}
}
return null;
}
function UpdateSortingUI()
{
var oOrderNode = oFetchXml.selectSingleNode("fetch/entity/order");
if (oOrderNode != null)
{
var sName = oOrderNode.getAttribute("attribute");
var bDescending = oOrderNode.getAttribute("descending") == "true";



for (var i = 0; i < cellsRow.cells.length - 1; i++)
{
var o = cellsRow.cells[i].all["imgSort"];
if (cellsRow.cells[i].name == sName)
{

with (o.style)
{
visibility = "visible";

if (bDescending)
{
filter = "flipv()";
o.alt = LOCID_ALT_COLUMNSORTORDER_DOWN;
}
else
{
filter = "";
o.alt = LOCID_ALT_COLUMNSORTORDER_UP;
}
}
if ( LOCID_UI_DIR=="RTL" )
{
if ( o.style.filter == "" )
o.style.filter = "fliph()" ;
else
o.style.filter += " fliph()" ;
}
}
else
{
o.style.visibility = "hidden";
o.alt = "";
}
}
}
}
function SetSort()
{
if (!_bInitialized)
{
return;
}
if (hasSortableColumns())
{

var oOrderNode = oFetchXml.selectSingleNode("fetch/entity/order");



if (IsNull(oOrderNode))
{
var sName = getFirstSortableColumn();
if (sName != null)
{
oOrderNode = oFetchXml.createElement("order");


oOrderNode.setAttribute("attribute", sName);
oOrderNode.setAttribute("descending","false");


oFetchXml.selectSingleNode("fetch/entity").appendChild(oOrderNode);
}
}

var oArgs					= new Object();
oArgs.oGridXml			= oGridXml;
oArgs.oPropertiesXml	= oPropertiesXml;
oArgs.oFieldsXml		= oFieldsXml;
oArgs.sSortCol			= oOrderNode.getAttribute("attribute");
oArgs.sEntityName		= _sPrimaryEntityName;
var aSetSort = openStdDlg(prependOrgName("/Tools/ViewEditor/Dialogs/SetSort.aspx?descend=" + oOrderNode.getAttribute("descending")), oArgs, 375, 250);
if (aSetSort)
{


oOrderNode.setAttribute("descending", aSetSort[0] ? "true" : "false");
oOrderNode.setAttribute("attribute", aSetSort[1]);
UpdateSortingUI();
}
UpdateFormData();
}
else
{
alert(LOCID_VIEWEDITOR_NOSRTBLFIELDS);
}
}
function hasSortableColumns()
{
var oNodes = oGridXml.selectNodes("//row/cell");
var iLen = oNodes.length;
for (var i=0; i < iLen; i++)
{
var sFieldName = oNodes[i].getAttribute("name");
if (isSortableField(oFieldsXml, _sPrimaryEntityName, sFieldName))
{
return true;
}
}
return false;
}
function Filter()
{
if (!_bInitialized)
{
return;
}
if (crmForm.queryapi.value != "")
{
alert(LOCID_VIEWEDITOR_FILTERCRITERIA);
return;
}

var oQFFilter;








if(crmForm.isquickfindquery.value == "1")
{

oQFFilter = oFetchXml.selectSingleNode("/fetch/entity/filter[@isquickfindfields=1]");


if(!IsNull(oQFFilter))
{

oFetchXml.selectSingleNode("/fetch/entity").removeChild(oQFFilter);
}
}
var o = new Object();
o.sFetchXml = oFetchXml.xml;
o.sLayoutXml = crmForm.layoutxml;
var oReturned = openStdDlg(prependOrgName("/Tools/ViewEditor/Dialogs/SetFilters.aspx?entityCode=" + crmFormSubmit.crmFormSubmitObjectTypeCode.value), o, 600, 600);
if (oReturned)
{

if (oReturned.bIsDirty)
{
oFetchXml.loadXML(oReturned.sFetchXml);


var oLinkEntityNodes = oFetchXml.selectNodes("fetch/entity/link-entity");
var sEntity, sFrom, sTo, sAlias;
for(var i=0; i<oLinkEntityNodes.length; i++)
{
with(oLinkEntityNodes[i])
{
sEntity = getAttribute("name");
sFrom = getAttribute("from");
sTo = getAttribute("to");
sAlias = getAttribute("alias");
}

var oEntityNode = oEntitiesXml.selectSingleNode("entities/entity[@name=\"" + sEntity + "\" and @fromattr=\"" + sFrom + "\" and @toattr=\"" + sTo + "\"]");
if(oEntityNode != null)
{
oEntityNode.setAttribute("alias", sAlias);
}
}
}

if(!IsNull(oQFFilter))
{
oFetchXml.selectSingleNode("/fetch/entity").appendChild(oQFFilter);
}
UpdateFormData();
}
}
function RemoveField(oActive)
{
var sFieldName = oActive.name;
var iFieldIndex = oActive.cellIndex;

GetGridRowNode(oGridXml).removeChild(GetGridCellNode(oGridXml, sFieldName));

try
{
removeFieldFromFetch(oFetchXml, sFieldName);
}
catch(e){}

var oRow	= oActive.parentElement;
var iIndex	= oActive.cellIndex;
oRow.deleteCell(iIndex);
_oActive = null;
UpdateDataArea();

var oNode = oFetchXml.selectSingleNode("/fetch/entity/order");
if (!IsNull(oNode) && sFieldName == oNode.getAttribute("attribute"))
{

var sName = getFirstSortableColumn();

if (sName != null)
{

oNode.setAttribute("attribute", sName);
UpdateSortingUI();
}
else
{

oNode.parentNode.removeChild(oNode);
}
}

UpdateFormData();
}
function removeFieldFromFetch(oFetchXml, sFieldName)
{
var oAttrNode = GetFetchAttributeNode(oFetchXml, sFieldName);
var oEntityNode = oAttrNode.parentNode;
oEntityNode.removeChild(oAttrNode);

var sVisible = oEntityNode.getAttribute("visible");
var bVisible = IsNull(sVisible) || sVisible == "true";
if(oEntityNode.nodeName == "link-entity" && oEntityNode.childNodes.length == 0 && !bVisible)
{

oEntityNode.parentNode.removeChild(oEntityNode);
}
}
function getFirstSortableColumn()
{
var i, sName;
var oNodes = oGridXml.selectNodes("//row/cell");
var iLen = oNodes.length;

for (i = 0; i < iLen; i++)
{
sName = oNodes[i].getAttribute("name");
if (isSortableField(oFieldsXml, _sPrimaryEntityName, sName))
{
break;
}
}
if (i < iLen)
{
return sName;
}
else
{
return null;
}
}
function AddField(oActive, oFieldObj, iWidth)
{

if (IsNull(iWidth))
{
iWidth = 100;
}
var sFieldName = oFieldObj.FieldName;
var bSetSorting = !hasSortableColumns();

var bSortableField = false;


var sEntityName	= _sPrimaryEntityName;
if(IsNull(oFieldObj.RelationshipId) || oFieldObj.RelationshipId.length == 0)
{
bSortableField = isSortableField(oFieldsXml, _sPrimaryEntityName, sFieldName);
}
else
{

sFieldName = oFieldObj.RelationshipId + "." + sFieldName;
sEntityName = oFieldObj.EntityName;
}

var oCell = oGridXml.createElement("cell");
oCell.setAttribute("name", sFieldName);
oCell.setAttribute("width", iWidth.toString());


if (!bSortableField)
{
oCell.setAttribute("disableSorting", "1");
}
if (oActive)
{
GetGridRowNode(oGridXml).insertBefore(oCell,GetGridCellNode(oGridXml, oActive.name).nextSibling);
}
else
{
GetGridRowNode(oGridXml).appendChild(oCell);
}
if (bSetSorting && bSortableField)
{


var oNode = oFetchXml.createElement("order")
oNode.setAttribute("attribute", sFieldName);
oNode.setAttribute("descending", "false");
GetFetchEntityNode(oFetchXml).appendChild(oNode);
}


addFieldToFetch(oFetchXml, oFieldObj, sFieldName, oEntitiesXml);
var iIndex = 0;

if (oActive)
{
iIndex = oActive.cellIndex + 1;
}

var newTd = CreateFieldCell(oCell);
cellsRow.insertBefore(newTd, cellsRow.cells(iIndex));
UpdateSortingUI();
UpdateDataArea();
newTd.click();
}
function addFieldToFetch(oFetchXml, oFieldObj, sFieldName, oEntitiesXml)
{
var oAttrNode = oFetchXml.createElement("attribute");
var oPrimaryEntityNode = GetFetchEntityNode(oFetchXml);

if(IsNull(oFieldObj.RelationshipId) || oFieldObj.RelationshipId.length == 0)
{

oAttrNode.setAttribute("name", sFieldName);
oPrimaryEntityNode.appendChild(oAttrNode);
}
else
{

var oFieldName = GetFieldAliasName(sFieldName);
var oLinkEntityNode = oFetchXml.selectSingleNode("fetch/entity/link-entity[@alias=\"" + oFieldName.Alias + "\"]");
if(oLinkEntityNode == null)
{
var oEntityNode = oEntitiesXml.selectSingleNode("entities/entity[@alias=\"" + oFieldName.Alias + "\"]");
oLinkEntityNode = oFetchXml.createElement("link-entity");
oLinkEntityNode.setAttribute("alias", oFieldName.Alias);
oLinkEntityNode.setAttribute("name", oFieldObj.EntityName);
oLinkEntityNode.setAttribute("from", oEntityNode.getAttribute("fromattr"));
oLinkEntityNode.setAttribute("to", oEntityNode.getAttribute("toattr"));
oLinkEntityNode.setAttribute("link-type", "outer");
oLinkEntityNode.setAttribute("visible", "false");
}
oAttrNode.setAttribute("name", oFieldObj.FieldName);
oLinkEntityNode.appendChild(oAttrNode);
oPrimaryEntityNode.appendChild(oLinkEntityNode);
}
}
function Move(bLeft)
{
if (!_bInitialized)
{
return;
}
if (_oActive)
{
bLeft ? MoveLeft() : MoveRight();
UpdateFormData();
}
else
{
alert(LOCID_VIEWEDITOR_MVSELECTCOLUMN);
}
}
function MoveLeft()
{

if (_oActive.previousSibling &&
!(_islookupview && _oActive.previousSibling.cellIndex == 0))
{
var oParentNode = GetGridRowNode(oGridXml);
var oSwapNode	= oParentNode.removeChild(GetGridCellNode(oGridXml, _oActive.name));
oParentNode.insertBefore(oSwapNode,GetGridCellNode(oGridXml, _oActive.previousSibling.name));

_oActive.swapNode(_oActive.previousSibling);
UpdateFormData();
}
}
function MoveRight()
{
if (_oActive.cellIndex < cellsRow.cells.length - 2 &&
!(_islookupview && _oActive.cellIndex == 0))
{
var oParentNode = GetGridRowNode(oGridXml);
var oSwapNode = oParentNode.removeChild(GetGridCellNode(oGridXml, _oActive.nextSibling.name));
oParentNode.insertBefore(oSwapNode,GetGridCellNode(oGridXml, _oActive.name));

_oActive.swapNode(_oActive.nextSibling);
UpdateFormData();
}
}
function UpdateFormData()
{
crmForm.layoutxml.value = Trim(oGridXml.xml);
crmFormSubmit.crmFormSubmitFetchXml.value = Trim(oFetchXml.xml);
}
function ValidateView()
{
if (oGridXml.selectSingleNode("/grid/row").childNodes.length <= 0)
{
alert(LOCID_VIEWEDITOR_NOFIELDS);
return false;
}
return true;
}
function addSortingToLookupView()
{
if (_islookupview)
{

var oOrderNode = oFetchXml.selectSingleNode("fetch/entity/order");


if (IsNull(oOrderNode))
{
oOrderNode = oFetchXml.createElement("order");


oOrderNode.setAttribute("attribute", _requiredColumn);
oOrderNode.setAttribute("descending","false");


oFetchXml.selectSingleNode("fetch/entity").appendChild(oOrderNode);
}
}
}
